package zzr.library.db.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Transaction;
import androidx.room.Update;

import java.util.List;

import zzr.library.db.obj.BorrowDO;
import zzr.library.db.obj.combine.BorrowWithBook;

@Dao
public interface BorrowDAO {

    @Transaction
    @Query("SELECT * FROM borrow WHERE rid = :rid")
    List<BorrowWithBook> selectByReaderId(int rid);

    @Insert
    void insert(BorrowDO borrowDO);

    /**
     * 查找此书的未归还记录
     */
    @Query("SELECT * FROM borrow WHERE bId = :bid AND returned = 0")
    BorrowDO selectNotReturn(int bid);

    @Update
    void update(BorrowDO borrowDO);
}
